﻿cmake_minimum_required(VERSION 3.10)
project(NDFrame LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)


if(NOT CMAKE_CONFIGURATION_TYPES AND NOT CMAKE_BUILD_TYPE)
    set(CMAKE_BUILD_TYPE Debug CACHE STRING "Build type" FORCE)
endif()

# 全局启用位置无关代码（适用于静态库被共享库引用）
set(CMAKE_POSITION_INDEPENDENT_CODE ON)

# 定义项目选项
option(BUILD_UDataFrame_LIBS "Build ZDataFrame static libraries" ON)
option(BUILD_UDataFrame_TEST "Build ZDataFrame static tests" ON)

set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin)


if (APPLE)
    set(OpenCV_DIR "/opt/homebrew/opt/opencv/lib/cmake/opencv4")
    find_package(OpenCV 4 REQUIRED CONFIG)
    message(STATUS "OpenCV 版本:    ${OpenCV_VERSION}")
    message(STATUS "OpenCV 包含目录: ${OpenCV_INCLUDE_DIRS}")
    message(STATUS "OpenCV 库:      ${OpenCV_LIBS}")


    set(ABSL_INCLUDE_DIR "/opt/homebrew/opt/abseil/include")
    set(ABSL_LIB_DIR "/opt/homebrew/opt/abseil/lib")
    message(STATUS "ABSL 包含目录: ${ABSL_INCLUDE_DIR}")
    message(STATUS "ABSL 库:      ${ABSL_LIB_DIR}")

    set(RE2_INCLUDE_DIR  "/opt/homebrew/opt/re2/include")
    set(RE2_LIB_DIR      "/opt/homebrew/opt/re2/lib")
    message(STATUS "RE2 包含目录: ${RE2_INCLUDE_DIR}")
    message(STATUS "RE2 库:      ${RE2_LIB_DIR}")
    list(APPEND EXTRA_INCLUDE_DIRS "/opt/homebrew/include")


    #========== 检查路径是否存在 =================
    if(NOT EXISTS "${RE2_INCLUDE_DIR}/re2/re2.h")
        message(FATAL_ERROR "RE2 头文件目录不存在: ${RE2_INCLUDE_DIR}/re2/re2.h")
    else ()
        message("RE2 头文件目录存在: ${RE2_INCLUDE_DIR}/re2/re2.h")
    endif()

    if(NOT EXISTS "${ABSL_INCLUDE_DIR}/absl/base/call_once.h")
        message(FATAL_ERROR "absl头文件目录不存在: ${ABSL_INCLUDE_DIR}/absl/base/call_once.h")
    else ()
        message("absl头文件目录存在: ${ABSL_INCLUDE_DIR}/absl/base/call_once.h")

    endif()
    message(STATUS "RE2 头文件目录: ${RE2_INCLUDE_DIR}")
    message(STATUS "absl 头文件目录: ${ABSL_INCLUDE_DIR}")
endif()


# UDataFrame模块条件编译
if(BUILD_UDataFrame_LIBS)
    add_subdirectory(UDataFrame)
    add_subdirectory(UDataFrame_test)
endif()

if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
    find_program(LSB_RELEASE_EXEC lsb_release)
    if(LSB_RELEASE_EXEC)
        execute_process(COMMAND ${LSB_RELEASE_EXEC} -is
                OUTPUT_VARIABLE LSB_RELEASE_ID
                OUTPUT_STRIP_TRAILING_WHITESPACE)
        message(STATUS "Linux distribution: ${LSB_RELEASE_ID}")
    endif()
elseif(APPLE)
    message(STATUS "Detected macOS platform")
elseif(CMAKE_SYSTEM_NAME STREQUAL "Windows")
    message(STATUS "Detected Windows platform")
    add_definitions(-D_WIN32_WINNT=0x0A00)
endif()
